using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using QFramework;
using UnityEditor;
using NotImplementedException = System.NotImplementedException;

namespace ProjectSurvival
{
    public partial class AbilitiesController : ViewController, IController
    {
        void Start()
        {
            var levelUpSystem = this.GetSystem<LevelUpSystem>();
            Global.SimpleSwordUnlocked.RegisterWithInitValue(b =>
            {
                if (b)
                {
                    SimpleSword.Show();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            Global.SimpleKnifeUnlocked.RegisterWithInitValue(b =>
            {
                if (b)
                {
                    SimpleKnife.Show();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            Global.SimpleRotateSworUnlocked.RegisterWithInitValue(b =>
            {
                if (b)
                {
                    SimpleRotateSword.Show();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            Global.SimpleBasketBallUnlocked.RegisterWithInitValue(b =>
            {
                if (b)
                {
                    SimpleBasketBall.Show();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

            var items = levelUpSystem.LevelUpItems.Where(item => item.IsWeapon)
                .OrderBy(x => Random.Range(0, levelUpSystem.LevelUpItems.Count())).FirstOrDefault();
            if (items != null) 
            {
                items.Upgrade();
            }
            else
            {
                Debug.Log("Item为空！");
            }

            Global.SuperBomb.RegisterWithInitValue(unlocked =>
            {
                if (unlocked)
                {
                    SuperBomItem.Show();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }

        public IArchitecture GetArchitecture()
        {
            return Global.Interface;
        }
    }
}